<?php
namespace App\Http\Controllers\Trends;
use App\Model\Trends;
use Illuminate\Http\Request;
use App\Http\Controllers\BaseApiController;
use App\Services\Trends\TrendsService;
use Illuminate\Support\Facades\DB;


class TrendsController extends BaseApiController{
    private $service;
    public function __construct(TrendsService $service){
        //继承基类的构造方法
        parent::__construct();
        //依赖注入service
        $this->service=$service;
    }
    /**
     * @return string
     * 航运空间 动态显示
     */
    public function sel()
    {
        //调用service层sel方法
        return $this->service->sel();
    }

    /**
     * 动态添加
     */
    public function add(Request $request)
    {
        $file=$request->post("img");
        $text=$request->post('text');
        if(empty($file)&&empty($text))
        {
            return $this->fail(205,'视频照片或者文字必须有一个');
        }
        $rule=['text' => "max:500"];
        if($error=$this->validate($rule,$request)){
            return $error;
        }

        return $this->service->add($request);
    }

    /**
     * 照片
     */
    public function addImg(Request $request)
    {

        if ($request->hasFile('file')) {

            return $this->service->addQiNiu($request);
        }
        else
        {
            return $this->fail(210,'没有照片');
        }
    }

    /***
     * 没用测试
     */
    public function bbb()
    {
        $array=[
            array('text'=>'不可能加班','num'=>1),
            array('text'=>'可以适当加班','num'=>2),
            array('text'=>'我爱加班','num'=>3),
            array('text'=>'天天加班都没事','num'=>4)
        ];
        echo json_encode($array);
    }
}




